'''
Created on 19.02.2012

@author: myaut
'''

import sys
sys.path.append('../../lib')

from salsa.util.rpc import RPCInfo, RPCClient, RPCDispatcher

class MathServer:    
    def sum(self, a, b = 1):
        return a + b
    
    def mul(self, a, b):
        return a * b

setattr(MathServer, 'rpc_info', RPCInfo())
MathServer.rpc_info.register(MathServer, 'sum', 'mul')

rpc_disp = RPCDispatcher(MathServer.rpc_info)
rpc_disp.bind(MathServer())

rpc_rq = RPCClient(MathServer.rpc_info, lambda rq: rpc_disp.process(rq))

print rpc_rq.sum(10)

try:
    print rpc_rq.mul(10)
except TypeError:
    pass

print rpc_rq.sum(20, 21)
print rpc_rq.mul(12, 11)